#include "rightclickmenu.h"

RightClickMenu::RightClickMenu(QWidget *parent) : QObject(parent)
{
    m_menu = new QMenu(parent);
    createActions();
    setupMenu();
}

RightClickMenu::~RightClickMenu()
{
    delete m_menu;
}

void RightClickMenu::show(const QPoint &pos)
{
    m_menu->exec(pos);
}

void RightClickMenu::createActions()
{
    // 创建各个菜单项
    m_refreshAction = new QAction(QIcon(":/icons/refresh.png"), tr("刷新"), this);
    m_copyAction = new QAction(QIcon(":/icons/copy.png"), tr("复制"), this);
    m_startAction = new QAction(QIcon(":/icons/start.png"), tr("开始"), this);
    m_stopAction = new QAction(QIcon(":/icons/stop.png"), tr("停止"), this);
    m_renameAction = new QAction(QIcon(":/icons/rename.png"), tr("重命名"), this);
    m_deleteAction = new QAction(QIcon(":/icons/delete.png"), tr("删除"), this);
    m_propertiesAction = new QAction(QIcon(":/icons/properties.png"), tr("属性"), this);
    m_separator = new QAction(this);
    m_separator->setSeparator(true);

    // 连接信号槽
    connect(m_refreshAction, &QAction::triggered, this, &RightClickMenu::onRefresh);
    connect(m_copyAction, &QAction::triggered, this, &RightClickMenu::onCopy);
    connect(m_startAction, &QAction::triggered, this, &RightClickMenu::onStart);
    connect(m_stopAction, &QAction::triggered, this, &RightClickMenu::onStop);
    connect(m_renameAction, &QAction::triggered, this, &RightClickMenu::onRename);
    connect(m_deleteAction, &QAction::triggered, this, &RightClickMenu::onDelete);
    connect(m_propertiesAction, &QAction::triggered, this, &RightClickMenu::onProperties);
}

void RightClickMenu::setupMenu()
{
    // 添加菜单项
    m_menu->addAction(m_refreshAction);
    m_menu->addAction(m_copyAction);
    m_menu->addSeparator();
    m_menu->addAction(m_startAction);
    m_menu->addAction(m_stopAction);
    m_menu->addSeparator();
    m_menu->addAction(m_renameAction);
    m_menu->addAction(m_deleteAction);
    m_menu->addSeparator();
    m_menu->addAction(m_propertiesAction);
}

void RightClickMenu::onRefresh()
{
    qDebug() << "Refresh triggered";
    emit refreshTriggered();
}

void RightClickMenu::onCopy()
{
    qDebug() << "Copy triggered";
    emit copyTriggered();
}

void RightClickMenu::onStart()
{
    qDebug() << "Start triggered";
    emit startTriggered();
}

void RightClickMenu::onStop()
{
    qDebug() << "Stop triggered";
    emit stopTriggered();
}

void RightClickMenu::onRename()
{
    qDebug() << "Rename triggered";
    emit renameTriggered();
}

void RightClickMenu::onDelete()
{
    qDebug() << "Delete triggered";
    emit deleteTriggered();
}

void RightClickMenu::onProperties()
{
    qDebug() << "Properties triggered";
    emit propertiesTriggered();
}
